#!/bin/bash -e

if [[ -z $1 ]]; then
  echo "Missing <TARGET>" >&2
  exit 1
fi

packager_bin() {
  local bin=$1
  local name=$(basename "$1")
  mkdir -p .packager/bin
  ln -s "../../$bin" ".packager/bin/$name"
}

TARGET=$1

cp -r "$PWD" "$TARGET"
cd "$TARGET"
bundle install --standalone --binstubs=binstubs --without=development test

rm -rf vendor/bundle/ruby/*/{bin,build_info,cache,doc,extensions,specifications}

packager_bin binstubs/cide
